function error_value = process_error_u_t_2d(mesh, pde, U, error_type)
t_end = pde.domain(6);
shift_u2 = mesh.Nb;
switch error_type
    case "Linf"
        err_E1 = 0;
        err_E2 = 0;
        for n = 1:mesh.Ne
            E = mesh.node(mesh.elem(n,:),:);
            V = E(1:3,:);
            [gauss_points_loc, ~] = gauss_lengdre_loc(V, "2d");
            phi = basis_function_loc(V, gauss_points_loc(:,1), gauss_points_loc(:,2), mesh.basis_type, "x");
            uh_E1 = phi * U(mesh.elem(n,:));
            uh_E2 = phi * U(mesh.elem(n,:)+shift_u2);
            f1 = max(abs(pde.u1(gauss_points_loc(:,1),gauss_points_loc(:,2),t_end) - uh_E1));
            f2 = max(abs(pde.u2(gauss_points_loc(:,1),gauss_points_loc(:,2),t_end) - uh_E2));
            if f1 > err_E1
                err_E1 = f1;
            end
            if f2 > err_E2
                err_E2 = f2;
            end
        end
        error_value = max(err_E1, err_E2);
    case "L2"
        err_E1 = 0;
        err_E2 = 0;
        for n = 1:mesh.Ne
            E = mesh.node(mesh.elem(n,:),:);
            V = E(1:3,:);
            [gauss_points_loc, gauss_weights_loc] = gauss_lengdre_loc(V, "2d");
            phi = basis_function_loc(V, gauss_points_loc(:,1), gauss_points_loc(:,2), mesh.basis_type, "x");
            uh_E1 = phi * U(mesh.elem(n,:));
            uh_E2 = phi * U(mesh.elem(n,:)+shift_u2);
            f1 = (pde.u1(gauss_points_loc(:,1),gauss_points_loc(:,2),t_end) - uh_E1).^2;
            f2 = (pde.u2(gauss_points_loc(:,1),gauss_points_loc(:,2),t_end) - uh_E2).^2;
            r1 = gauss_weights_loc * f1;
            r2 = gauss_weights_loc * f2;
            err_E1 = err_E1 + r1;
            err_E2 = err_E2 + r2;
        end
        error_value = sqrt(err_E1 + err_E2);
    case "H1"
        err_E1x = 0;
        err_E1y = 0;
        err_E2x = 0;
        err_E2y = 0;
        for n = 1:mesh.Ne
            E = mesh.node(mesh.elem(n,:),:);
            V = E(1:3,:);
            [gauss_points_loc, gauss_weights_loc] = gauss_lengdre_loc(V, "2d");
            phix = basis_function_loc(V, gauss_points_loc(:,1), gauss_points_loc(:,2), mesh.basis_type, "dx");
            phiy = basis_function_loc(V, gauss_points_loc(:,1), gauss_points_loc(:,2), mesh.basis_type, "dy");
            uh_E1x = phix * U(mesh.elem(n,:));
            uh_E1y = phiy * U(mesh.elem(n,:));
            uh_E2x = phix * U(mesh.elem(n,:)+shift_u2);
            uh_E2y = phiy * U(mesh.elem(n,:)+shift_u2);
            f1x = (pde.u1dx(gauss_points_loc(:,1),gauss_points_loc(:,2),t_end) - uh_E1x).^2;
            f1y = (pde.u1dy(gauss_points_loc(:,1),gauss_points_loc(:,2),t_end) - uh_E1y).^2;
            f2x = (pde.u2dx(gauss_points_loc(:,1),gauss_points_loc(:,2),t_end) - uh_E2x).^2;
            f2y = (pde.u2dy(gauss_points_loc(:,1),gauss_points_loc(:,2),t_end) - uh_E2y).^2;
            r1x = gauss_weights_loc * f1x;
            r1y = gauss_weights_loc * f1y;
            r2x = gauss_weights_loc * f2x;
            r2y = gauss_weights_loc * f2y;
            err_E1x = err_E1x + r1x;
            err_E1y = err_E1y + r1y;
            err_E2x = err_E2x + r2x;
            err_E2y = err_E2y + r2y;
        end
        error_value = sqrt(err_E1x + err_E1y + err_E2x + err_E2y);
    otherwise
        error("Invalid error type.");
end
end